package com.vma.jifu.controller;

import com.jfinal.core.Controller;
import com.vma.jifu.service.AccountService;
import com.vma.jifu.service.AgentService;
import com.vma.jifu.service.UserService;
import com.vma.jifu.service.impl.AccountServiceImpl;
import com.vma.jifu.service.impl.AgentServiceImpl;
import com.vma.jifu.service.impl.UserServiceImpl;

/**
 * Created by chenzui on 2017/6/21.
 */
public class UserController extends BaseController {
    private UserService userService = new UserServiceImpl();

    private AccountService accountService = new AccountServiceImpl();

    private AgentService agentService = new AgentServiceImpl();

    public void login(){
        String loginAccout = getPara("loginAccount");
        String password = getPara("password");

        renderRes(userService.login(loginAccout,password));
    }

    public void sendSms(){
        String phone = getPara("phone");
        renderRes(userService.sendSms(phone));
    }

    public void signUp(){
        String phone = getPara("phone");
        String smsCode = getPara("smsCode");
        String pwd = getPara("pwd");
        String smsId = getPara("smsId");
        String openId = getPara("openId");
        Integer parentId =  getParaToInt("parentId");
        renderRes(userService.signUp(phone,smsCode,pwd,smsId,openId,parentId));
    }

    public void findPwd(){
        String phone = getPara("phone");
        String smsCode = getPara("smsCode");
        String pwd = getPara("pwd");
        String smsId = getPara("smsId");
        userService.findPwd(phone,smsCode,pwd,smsId);
        renderRes("success");
    }


    public void getProtocol(){
        renderRes(userService.getUserProtocol());
    }

    public void getUserCenterInfo(){
        Integer userId = getParaToInt("id");
        renderRes(userService.getUserCount(userId));
    }

    public void updateUserInfo(){
        Integer userId = getParaToInt("id");
        String parentUser = getPara("parent");
        String imgUrl  = getPara("imgUrl");
        String nickName = getPara("nickName");
        userService.updateUserInfo(userId,parentUser,imgUrl,nickName);
        renderRes("success");
    }

    public void modifyPhone(){
        Integer userId = getParaToInt("id");
        String phone = getPara("phone");
        String smsCode = getPara("smsCode");
        String smsId = getPara("smsId");
        userService.updateUserPhone(userId,phone,smsId,smsCode);
        renderRes("success");
    }

    public void tgIndex(){
        Integer userId = getParaToInt("id");
        renderRes(userService.qryUserAwards(userId));
    }

    public void ucIndex(){
        Integer userId = getParaToInt("id");
        renderRes(userService.ucIndex(userId));

    }

    public void getMyAccount(){
        Integer userId = getParaToInt("userId");
        renderRes(accountService.getMyAccount(userId));
    }

    public void addAccount(){
        Integer userId = getParaToInt("userId");
        String aliName = getPara("aliName");
        String aliAccount = getPara("aliAccount");
//        String bankUserName = getPara("bankUserName");
//        String cardNumber = getPara("cardNumber");
//        String bankName = getPara("bankName");
//        String location = getPara("location");
        String wxName = getPara("wxName");
        String wxAccount = getPara("wxAccount");
        accountService.addAccount(userId,aliName,aliAccount,wxName,wxAccount);
        renderRes("success");

    }

    /**
     * 查询是否折扣
     */
    public void discount(){
        Integer userId = getParaToInt("userId");
        renderRes(userService.discount(userId));
    }

    /**
     * 提现
     */
    public void checkOutMoney(){
        Integer userId = getParaToInt("userId");
        Integer type = getParaToInt("type");
        Integer number = getParaToInt("number");
        Integer accountId = getParaToInt("accountId");
        accountService.checkOutMoney(userId,type,number,accountId);
        renderRes("success");
    }
    public void qryCashOutList(){
        Integer userId = getParaToInt("userId");
        Integer cPage = getParaToInt("cPage");
        Integer pSize = getParaToInt("pSize");
        renderRes(accountService.qryCashOutList(userId,cPage,pSize));

    }

    /**
     * 代理页面初始化
     */
    public void initAgentPage(){
        Integer userId = getParaToInt("userId");
        renderRes(agentService.initAgentPage(userId));
    }

    public void loginByWx(){
        String code = getPara("code");
        renderRes(userService.loginByWx(code));
    }
}
